<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>cesium示例</title>
</head>
<!--Cesium js文件引入 -->
<script src="./js/earthsdk.js"></script>
<!-- 自定义Css样式 -->
<link rel="stylesheet" href="./css/example1.css" />

<style>
    html,
    body {
        width: 100%;
        height: 100%;
        margin: 0px;
        padding: 0px;
    }

    #app {
        position: relative;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }

    button {
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 999;
    }
</style>

<body>
    <div id="app"></div>
    <button onclick="isShowRedBox()">红色盒子显/隐</button>

    <script>
        /** -----------------------------------------地球创建----------------------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;

        var redBox;
        // 监听视口状态
        objm.viewerCreatedEvent.don((v) => {
            // 获取Cesium底层viewer
            const viewer = v.viewer;
            // 创建红色盒子添加到viewer上
            redBox = viewer.entities.add({
                name: "Red box with black outline",
                position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
                box: {
                    dimensions: new Cesium.Cartesian3(400000.0, 400000.0, 400000.0),
                    material: Cesium.Color.RED.withAlpha(0.5),
                    outline: true,
                    outlineColor: Cesium.Color.BLACK,
                },
            });
            viewer.zoomTo(viewer.entities);
        });
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            id: "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            type: "ESImageryLayer",
            url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
        });


        // 红色盒子显示/隐藏
        const isShowRedBox = () => {
            redBox.show = !redBox.show;
        };
    </script>
</body>

</html>